//
//  WalletDefaults.m
//  MyWallet
//
//  Created by 小肥羊 on 15/7/17.
//  Copyright (c) 2015年 小肥羊. All rights reserved.
//

#import "WalletDefaults.h"

@implementation WalletDefaults

+ (void)initValue
{
    if (![[NSUserDefaults standardUserDefaults] boolForKey:_DSetting]) {
        //设置初始值
        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:_DSetting];
    }
}


#pragma mark - 保存
+ (void)saveTotalAssets:(TotalAssets *)totalAssets
{
    [[NSUserDefaults standardUserDefaults] setObject:[WalletDefaults totalAssetsToDict:totalAssets] forKey:_DWallet];
}

+ (NSMutableDictionary *)getTotalAssetsDict
{
    return [[NSUserDefaults standardUserDefaults] objectForKey:_DWallet];
}

#pragma mark - 转化
+ (NSMutableDictionary *)totalAssetsToDict:(TotalAssets *)totalAssets
{
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
    [dict setObject:[NSString stringWithFormat:@"%@", @(totalAssets.walletMoney)] forKey:@"walletMoney"];
    [dict setObject:[self cardToDict:totalAssets.card1] forKey:@"card1"];
    [dict setObject:[self cardToDict:totalAssets.card2] forKey:@"card2"];
    [dict setObject:[self cardToDict:totalAssets.card3] forKey:@"card3"];
    [dict setObject:[self cardToDict:totalAssets.card4] forKey:@"card4"];
    [dict setObject:[self cardToDict:totalAssets.card5] forKey:@"card5"];
    [dict setObject:[self cardToDict:totalAssets.card6] forKey:@"card6"];
    return dict;
}

+ (NSMutableDictionary *)cardToDict:(CardModel *)card
{
    NSMutableDictionary *cardDict = [[NSMutableDictionary alloc] init];
    [cardDict setObject:card.cardName forKey:@"cardName"];
    [cardDict setObject:[NSString stringWithFormat:@"%@", @(card.cardMoney)] forKey:@"cardMoney"];
    [cardDict setObject:[NSString stringWithFormat:@"%@", @(card.isActivation)] forKey:@"isActivation"];
    return cardDict;
}


@end
